import { Global, Module } from '@nestjs/common';
import { CachingService } from './caching.service';
import { BaseCacheModule } from '@app/base-cache';
import { CacheModule } from '@nestjs/cache-manager';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { redisStore } from 'cache-manager-ioredis-yet'

@Global()
@Module({
  imports : [
    CacheModule.registerAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          store: redisStore,
          ...config.get('cache')
        }
      }
    })
    ,BaseCacheModule],
  providers: [CachingService],
  exports : [CachingService]
})
export class CachingModule {}
